<template>
  <div class="shop_detail">
    <div class="behind_img" v-if="shopDetail">
      <!-- <img :src="imageUrl + shopDetail.behind_img" alt="" /> -->
      <!-- 测试图片 -->
      <img src="@/assets/images/05.jpg" alt="" />
    </div>
    <section class="container" v-if="shopDetail">
      <div class="content">
        <div class="header">
          <div class="avatar">
            <!-- <img :src="imageUrl + shopDetail.shop_avatar" alt="" /> -->
            <!-- 测试图片 -->
            <img src="@/assets/images/37.jpg" alt="" />
          </div>
          <section>
            <div class="title">{{ shopDetail.name }}</div>
            <span class="sales">月销：{{ shopDetail.sale }}</span
            >&nbsp;
            <span class="delivery_time">配送约30分钟</span>
          </section>
        </div>
        <p class="notice">公告：{{ shopDetail.notice }}</p>
      </div>
      <section class="activity" @click="showActivty">
        <div class="activity_name" v-if="activityList.length">
          <li
            :style="{ backgroundColor: activityList[0].icon_color }"
            class="icon_name"
          >
            {{ activityList[0].icon_name }}
          </li>
          <li>{{ activityList[0].name }}</li>
        </div>
        <div class="more">
          <span>{{ activityList.length }}个活动</span>
          <i class="iconfont icon-zuojiantou"></i>
        </div>
      </section>
    </section>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
import { imageUrl } from '@/config/env';
import { getShopDetail, ShopActivity } from '@/network/getData';

export default {
  data() {
    return {
      imageUrl,
      shopDetail: null,
      activityList: []
    };
  },
  components: {},
  created() {
    this.initData();
  },
  computed: {
    ...mapState(['shop_id'])
  },
  methods: {
    ...mapMutations(['SAVE_SHOP_DETAIL']),
    async initData() {
      // 获取店铺详细
      const shop = await getShopDetail(this.shop_id);
      this.shopDetail = shop.data;
      this.SAVE_SHOP_DETAIL(this.shopDetail);
      // 获取店铺活动
      const activity = await ShopActivity(this.shop_id);
      this.activityList = activity.data;
    },
    showActivty() {
      this.$emit('showActivty', this.activityList);
    }
  }
};
</script>

<style lang="less" scoped>
.shop_detail {
  width: 100%;
  height: 185px;
  background-color: #fff;
  position: relative;
  .behind_img {
    position: absolute;
    top: -100px;
    left: 0;
    img {
      width: 100%;
      filter: brightness(50%);
    }
  }
  .container {
    position: absolute;
    left: 50%;
    bottom: 9px;
    transform: translateX(-50%);
    width: 95%;
    border-radius: 5px;
    box-shadow: 0 2px 3px 1px #ccc;
    background-color: #fff;
    .content {
      font-size: var(--font-min);
      padding: 10px;
      .header {
        display: flex;
        margin-bottom: 7px;
      }
      img {
        width: 50px;
        height: 50px;
        border-radius: 5px;
        margin-right: 10px;
      }
      .title {
        margin-bottom: 7px;
        font-size: 18px;
        color: #222;
      }
      .notice {
        font-size: var(--font-min);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .activity {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px;
      background-color: #f5f5f5;
      color: #222;
      border-radius: 0 0 5px 5px;
      font-size: var(--font-min);
      li {
        display: inline;
        margin-right: 5px;
      }
      .icon_name {
        padding-left: 3px;
      }
      .more {
        display: flex;
        align-items: center;
        i {
          display: inline-block;
          transform: rotate(180deg);
        }
      }
    }
  }
}
</style>
